[in progress] Abilities API: Add a core/settings ability#12141
[in progress] Abilities API: Add a core/settings ability#12141jorgefilipecosta wants to merge 3 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
@jorgefilipecosta can you link this to the trac ticket please? I don't have edit perms in this repo. |
073df67 to
c948c7a
Compare
Nice catch the ticket mention was added. |
Add a read-only core/settings ability that returns WordPress settings as a flat name => value map. Only settings flagged with the new show_in_abilities registration arg are exposed; callers can filter by settings group or by name (mutually exclusive). Requires the manage_options capability. The logic lives in a new internal WP_Settings_Abilities class, structured so a future core/manage-settings write ability can reuse its helpers.
'settings' reads more naturally than 'slugs' for filtering an abilities-exposed settings map by name.
c948c7a to
a28c976
Compare
… tests Register a setting with show_in_abilities and assert it is exposed in the ability's input enum, output schema, and execute output.
Part of: WordPress/ai#40
Ticket: https://core.trac.wordpress.org/ticket/64605
Summary
Adds a read-only
core/settingsability to the Abilities API. It returns WordPress settings — those flagged with a newshow_in_abilitiesregistration arg — as a flatname => valuemap, with per-setting metadata (type, title, description, default) carried in the output schema. Callers can filter by settingsgroupor bysettingsname (mutually exclusive). Requiresmanage_options.This is a flat-output alternative to #10747. The logic lives in a new internal
WP_Settings_Abilitiesclass (src/wp-includes/abilities/class-wp-settings-abilities.php), structured so a futurecore/manage-settingswrite ability can reuse its helpers (get_exposed_settings(),value_schema(),cast_value()).Test plan
In wp-admin, open the browser console and call the ability's run endpoint with
wp.apiFetch:name => valuemap with typed values (e.g.posts_per_pageis an int,use_smiliesa bool)groupandsettingsfilters narrow the result; supplying both at once is rejectedmanage_options) is deniedPHPUnit coverage added in
tests/phpunit/tests/abilities-api/wpRegisterCoreSettingsAbility.php(including a test that a setting registered withshow_in_abilitiesis exposed by the ability).